package pl.polidea.imf.blackberry.util;

import net.rim.device.api.system.Application;
import net.rim.device.api.system.Clipboard;
import net.rim.device.api.system.EventInjector;
import net.rim.device.api.system.KeypadListener;
import net.rim.device.api.ui.Keypad;

public class SystemLogHelper {

	public static String getSystemLogs() {

		Application.getApplication().requestBackground();
		ThreadHelper.tryToSleep(2000);
		EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, 'L', KeypadListener.STATUS_ALT));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, 'G', KeypadListener.STATUS_ALT));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, 'L', KeypadListener.STATUS_ALT));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, 'G', KeypadListener.STATUS_ALT));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_MENU, KeypadListener.STATUS_NOT_FROM_KEYPAD));

		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_ROLL_DOWN, 4, KeypadListener.STATUS_NOT_FROM_KEYPAD));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_CLICK, 1, KeypadListener.STATUS_NOT_FROM_KEYPAD));
		ThreadHelper.tryToSleep(1000);

		EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_CLICK, 1, KeypadListener.STATUS_NOT_FROM_KEYPAD));
		ThreadHelper.tryToSleep(500);
		EventInjector.invokeEvent(new EventInjector.TrackwheelEvent(EventInjector.TrackwheelEvent.THUMB_UNCLICK, 1, KeypadListener.STATUS_NOT_FROM_KEYPAD));
		ThreadHelper.tryToSleep(2000);
		Application.getApplication().requestForeground();
		Clipboard clip = Clipboard.getClipboard();
		
				
		return ( clip == null ? "" : clip.toString());
	}
}
